const app = getApp()
const WXAPIOLD = require("../../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, // 是否显示左上角图标   1表示显示    0表示不显示
      title: '我要刷卡', // 导航栏 中间的标题
      textColor: '#fff', // 标题颜色
      bgColor: '', // 导航栏背景颜色
      isColor: false,
      isScrollY: '',
      isShare: '' //是否来自分享 0 :不是，1：是
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight: app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //唤醒扫一扫功能
  getScancode: function() {
    var that = this;
    // 允许从相机和相册扫码
    wx.scanCode({
      success: (res) => {
        console.log(res.result)
        let parameter = res.result.split("code=")[1];
        console.log(parameter)
        let result = JSON.parse(parameter)

        console.log(result)
        console.log("扫一扫参数",result.param)
        console.log("扫一扫类型",result.type) 
        console.log("扫一扫类型",result.staffId)
        if(result.type==1){
          wx.navigateTo({
            url: '/userPageA/pages/scan/information/information?param=' + result.param
          })
        }else if(result.type==2){
          wx.navigateTo({
            url: '/userPageA/pages/scan/receiving_assets/receiving_assets?param=' + result.param
          })
        }else if(result.type==4){
          this.setData({
            qrCodeUrl: result.param,
            staffId: result.staffId
          })
          this.getParCollectionQrCodeUrl()
        }
        else if(result.type==5){ //退卡页面
          wx.navigateTo({
            url: '/userPageB/pages/returnCard/returnCard?param=' + result.param
          })
        }
        else{
          console.log('else')
        }
      },
      fail:(res)=>{
        console.log(res)
      }
    })
  },
  //解析二维码confirmInfo
  getParCollectionQrCodeUrl(){
   
    var data = {
      qrCodeUrl:this.data.qrCodeUrl,
    }
    WXAPIOLD.parCollectionQrCodeUrl(data, (res) =>{
      const data = res.result
      console.log("解析二维码",res)
      if(res.code === 200){
        var merchantId = data.merchantId
        console.log('this.data.staffId',this.data.staffId)
        wx.navigateTo({
          // url: '/pages/pay/pay?QRmerchantId='+merchantId,   
          url: '/pages/pay/payTransit/payTransit?QRmerchantId='+merchantId+'&staffId='+this.data.staffId, 
        })
      }else{
        wx.showToast({
          title: res.message,
          icon: 'none'
        })
      }
    })
  },
  /*
   * 页面滚动
   **/
  onPageScroll(e) {
    var that = this;
    var scrollY = e.scrollTop
    if (scrollY > 50) {
      that.setData({
        ['nvabarData.textColor']: '#000',
        ['nvabarData.isScrollY']: true,
        ['nvabarData.isColor']: true,
      })
      wx.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: '#000000',
      })
    } else if (scrollY < 50) {
      that.setData({
        ['nvabarData.textColor']: '#fff',
        ['nvabarData.isScrollY']: false,
        ['nvabarData.isColor']: false,
      })
      wx.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: '#ffffff',
      })
    }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  // onPullDownRefresh: function () {

  // },

  /**
   * 页面上拉触底事件的处理函数
   */
  // onReachBottom: function () {

  // },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})